package com.qingzhou.framework.dto;

import com.qingzhou.common.web.domain.LoginUser;
import com.qingzhou.common.web.domain.SysUser;
import lombok.Data;
import lombok.Getter;

import java.io.Serializable;
import java.util.Set;

/** 当前登录用户信息 */
@Data
public class CurrentUser implements Serializable {

    /** 系统用户 */
    private SysUser user;

    /** 当前用户所拥有的角色编码 */
    private Set<String> roles;

    /** 当前用户所用友的权限编码 */
    private Set<String> permissions;


    /**
     * 将登录用户转换为当前用户
     * @param loginUser 登录用户
     * @return 当前用户
     */
    public static CurrentUser of(LoginUser loginUser) {
        CurrentUser currentUser = new CurrentUser();
        currentUser.setUser(loginUser.getSysUser());
        currentUser.setRoles(loginUser.getRoles());
        currentUser.setPermissions(loginUser.getPermissions());
        return currentUser;
    }
}
